<?php
namespace mobile\controllers;

use Yii;
use yii\base\InvalidParamException;
use yii\web\BadRequestHttpException;
use yii\web\Controller;
use yii\filters\VerbFilter;
use yii\filters\AccessControl;
use common\models\user\LoginForm;
use frontend\models\PasswordResetRequestForm;
use frontend\models\ResetPasswordForm;
use frontend\models\SignupForm;
use frontend\models\ContactForm;
use common\models\user\User;
use common\models\member\Member;
use common\models\category\Category;
use common\models\articles\Articles;
use common\models\meeting\Meeting;
use zhongkefu\zhongkefu;
use zhongkefu\helpers\Utils;



/**
 * Site controller
 */
class SiteController extends Controller
{
    /**
     * @inheritdoc
     */
     public $layout = 'firstpage'; 
    public function behaviors()
    {
        return [
            'access' => [
                'class' => AccessControl::className(),
                'only' => ['logout', 'signup'],
                'rules' => [
                    [
                        'actions' => ['signup'],
                        'allow' => true,
                        'roles' => ['?'],
                    ],
                    [
                        'actions' => ['logout'],
                        'allow' => true,
                        'roles' => ['@'],
                    ],
                ],
            ],
            'verbs' => [
                'class' => VerbFilter::className(),
                'actions' => [
                    'logout' => ['post'],
                ],
            ],
        ];
    }

    /**
     * @inheritdoc
     */
    public function actions()
    {
        return [
            'error' => [
                'class' => 'yii\web\ErrorAction',
            ],
            'captcha' => [
                'class' => 'yii\captcha\CaptchaAction',
                'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null,
            ],
        ];
    }

    /**
     * Displays homepage.
     *
     * @return mixed
     */
    public function actionIndex()
    {
        if(!Utils::isMobile()){
            $url = Yii::$app->params['frontendurl'];
            header("Content-type: text/html; charset=utf-8");
            Header("Location: $url");
            exit;
        }
        $conf = false;
        $curpage = !empty(Yii::$app->request->get()["per-page"])?"_".intval(Yii::$app->request->get()["per-page"]):'';
        $filedir = "staticfile/";
        $name = Yii::$app->controller->id."_".Yii::$app->controller->action->id;
        $fail = $curpage.".html";
        $filename = $filedir.$name.$fail;
        if($conf){
            if(!file_exists($filename)){
                $file = $this->render('index',['model'=>'Congratulations!'],true);
                file_put_contents($filename, $file);
            }
            echo file_get_contents($filename);
        }else{
            return $this->render('index',[
            'model'=>'Congratulations!',
            ]);
        }

    }




}
